//
//  StoryDetailController.m
//  Backhoe
//
//  Created by Charlie Morss on 11/15/08.
//  Copyright 2008 AdReady. All rights reserved.
//

#import "StoryDetailController.h"
#import "DetailTitleCell.h"

@implementation StoryDetailController

@synthesize story;

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

- (void)awakeFromNib {
//	//Create a button
//	UIBarButtonItem *infoButton = [[UIBarButtonItem alloc]
//	initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];
//
//	[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
}

- (WebController *)webController {
    // Instantiate the detail view controller if necessary.
    if (webController == nil) {
        webController = [[WebController alloc] initWithNibName:@"WebController" bundle:nil];
    }
    return webController;
}

- (IBAction)diggItClicked:(id)sender {
	NSLog(@"Digg it!!");
}

- (void)viewWillDisappear:(BOOL)animated {
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	[tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if (section == 0) {
    return 1;
	}
	else {
		return 5;
	}
}


- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *commentCellIdentifier = @"Comment";
		
		if (indexPath.section == 0) {
			titleCell.titleLabel.text = @"foo";
			titleCell.rankLabel.text = @"123";
			return titleCell;
		}
		else {
    
			UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:commentCellIdentifier];
			if (cell == nil) {
					cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:commentCellIdentifier] autorelease];
			}
			cell.text = @"vivek";
			// Configure the cell
			return cell;
		}
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section {
	if (section == 0) {
		return nil;
	} else {
		return @"Comments";
	}
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	if (indexPath.section == 0) {
		UIFont *aFont = [titleCell font];

		// Get the width of a string when wrapping within a particular width
		CGSize size = [story.title sizeWithFont:aFont
                              constrainedToSize:CGSizeMake(titleCell.frame.size.width, 3000)
      		                lineBreakMode:UILineBreakModeWordWrap];
												
		return size.height;
	}
	else {
		return 44.0f;
	}
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	if (indexPath.section == 0) {
		BackhoeAppDelegate *appDelegate = (BackhoeAppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate.navigationController pushViewController:[self webController] animated:YES];
		[webController loadUrl:@"http://m.digg.com"];
	}
}

/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
    }
    if (editingStyle == UITableViewCellEditingStyleInsert) {
    }
}
*/

/*
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
}
*/
/*
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
*/

- (void)dealloc {
    [super dealloc];
}


@end

